#ifndef _TWITALK_TWITTER_H__
#define _TWITALK_TWITTER_H__


#include "vmio.h"
#include "vmchset.h"
#include "vmhttp.h"
#include "vmstdlib.h"

#include "common.h"


#define TWITTER_TEXT_LEN 561

struct twitter_account
{
  VMCHAR *account;
  VMCHAR *password; 
  VMCHAR *last_text_id; /** last home timeline text id*/
};

struct twitter_user
{
	VMINT user_id;
	VMCHAR *user_name;
};

struct twitter_status
{
  VMCHAR text[TWITTER_TEXT_LEN];
  VMINT16 text_len;
  VMCHAR *text_id;
  struct tm text_time;
  struct twitter_user user;
  struct twitter_status *next;
};

//jack add
extern VMINT http_handle;


/** returns the 20 most recent statuses, including retweets, posted by the authenticating user and that user's friends. 
	@param account twitter account info
	@param http_hook_cb callback function 
	@return 0 success, -1 false;
*/
int tw_home_timeline (struct twitter_account *account, void (*http_hook_cb)(VMINT bResponse, void* pSession));

/** returns the 20 most recent statuses from non-protected users who have set a custom user icon.
	@param http_hook_cb callback function 
	@return 0 success, -1 false;
*/
int tw_public_timeline (void (*http_hook_cb)(VMINT bResponse, void* pSession));

/** returns the 20 most recent statuses posted from the authenticating user. 
	@param account twitter account info
	@param user_id user_id = 0 will return current user's timeline.
	@return 0 success, -1 false;
*/
int tw_user_timeline (struct twitter_account *account, VMINT32 user_id, void (*http_hook_cb)(VMINT bResponse, void* pSession));

/** return the 20 most recent mentions (status containing @username) for the authenticating user.
	@param account twitter account info
	@param http_hook_cb callback function 
	@return 0 success, -1 false;
*/
int tw_mentions_timeline(struct twitter_account *account, void (*http_hook_cb)(VMINT bResponse, void* pSession));

/** return the 20 recent direct messages sent to the authenticating user.
	@param account twitter account info
	@param http_hook_cb callback function 
	@return 0 success, -1 false;
*/

int tw_direct_timeline (struct twitter_account *account, void (*http_hook_cb)(VMINT bResponse, void* pSession));

/** recent favorite statuses for the authenticating user or user specified by the ID parameter
	@param account twitter account info
	@param user_id user_id = 0 will return current user's timeline.
	@param http_hook_cb callback function 
	@return 0 success, -1 false;
*/
int tw_favorites_timeline(struct twitter_account *account, VMINT32 user_id, void (*http_hook_cb)(VMINT bResponse, void* pSession));

/** Updates the authenticating user's status.
	@param account twitter account info
	@param text user's status , must be utf8
	@param text_len user's status length
	@param http_hook_cb callback function 
	@return 0 success, -1 false, 1 other error;
*/
int tw_update(struct twitter_account *account, VMCHAR *text, VMINT text_len, void (*http_hook_cb)(VMINT bResponse, void* pSession));

/** Destroys the status specified by the required ID parameter.
	@param account twitter account info
	@param text_id the status id of your status which you want destroy
	@param http_hook_cb callback function 
	@return 0 success, -1 false , 1 other error;
*/
int tw_destroy(struct twitter_account *account, VMCHAR *text_id, void (*http_hook_cb)(VMINT bResponse, void* pSession));

/** Sends a new direct message to the specified user from the authenticating user
	@param account twitter account info
	@param text the direct message
	@param text_len the dm length
	@param user_id user id who you want send this direct message
	@param http_hook_cb callback function 
	@return 0 success, -1 false;
*/
int tw_direct_new(struct twitter_account *account, VMCHAR *text, VMINT text_len, VMINT32 user_id, void (*http_hook_cb)(VMINT bResponse, void* pSession));

/** Destroys the direct message specified in the required ID parameter. 
	@param account twitter account info
	@param text_id the id of the direct message which you want destroy
	@param http_hook_cb callback function 
	@return 0 success, -1 false;
*/
int tw_direct_destroy(struct twitter_account *account, VMCHAR *text_id, void (*http_hook_cb)(VMINT bResponse, void* pSession));


/** Favorites the status specified in the ID parameter as the authenticating user. 
	@param account twitter account info
	@param text_id the id of the favorites message which you want add
	@param http_hook_cb callback function 
	@return 0 success, -1 false;
*/
int tw_favorites_create(struct twitter_account *account, VMCHAR *text_id, void (*http_hook_cb)(VMINT bResponse, void* pSession));

/** Un-favorites the status specified in the ID parameter as the authenticating user.
	@param account twitter account info
	@param text_id the id of the favorites message which you want destroy
	@param http_hook_cb callback function 
	@return 0 success, -1 false;
*/
int tw_favorites_destroy(struct twitter_account *account, VMCHAR *text_id, void (*http_hook_cb)(VMINT bResponse, void* pSession));


#define TWITTER_PROCESS_SUCCESS 0
#define TWITTER_PROCESS_NET_ERROR -1
#define TWITTER_PROCESS_AUTHOR_ERROR -2
#define TWITTER_PROCESS_OTHER_ERROR 1

/** deal with the returns xml by twitter api
    @param bResponse response of http request
    @param pSession data from http response
    @param statuses if success return twitter status chain else return NULL
    @return 0, -1, -2, 1 if success, network error, authorization fail if is send dm it means u can not send dm to this user, other error
*/
int twitter_cb_process(VMINT bResponse, void* pSession, struct twitter_status **statuses);

/** free twitter statuses chain
    @param statuses the twitter statues chain
*/
void twitter_free(struct twitter_status **statuses);

void twitter_cb_test(VMINT bResponse, void* pSession);

#endif
